package main

import (
	"github.com/name5566/leaf"
	"talent.com/agency_im/common/interceptors"
	"talent.com/agency_im/common/interceptors/builtin"
	_ "talent.com/agency_im/common/pay/integrated" // 注册支付功能插件
	"talent.com/agency_im/common/utils/frequency"
	"talent.com/agency_im/conf"
	"talent.com/agency_im/modules/core"
	"talent.com/agency_im/modules/gate"
	"talent.com/agency_im/modules/http"
	"talent.com/server/durotar.git/log"
)

func init() {
	//注册消息发送限流拦截器
	defaultLimiter := &frequency.MemoryLimiter{}
	defaultLimiter.RegisterRules(map[string]frequency.LimiterRule{
		"SEND_MSG": {5, 10}, // 发送消息频率限制：每10秒最多发送5条消息
	})
	interceptors.RegisterMessageInterceptor(&builtin.FrequencyLimiterInterceptor{
		Limiter: defaultLimiter,
	})
	// 注册消息发送检查黑名单
	interceptors.RegisterMessageInterceptor(&builtin.BlacklistInterceptor{})
	//注册用户被禁用
	interceptors.RegisterMessageInterceptor(&builtin.CheckUserStatusInterceptor{})
	// 检查用户暂离
	interceptors.RegisterMessageInterceptor(&builtin.UserLeavingInterceptor{})
}

func main() {
	conf.InitConfig()

	defer onClose()

	leaf.Run(
		gate.Module,
		core.Module,
		http.Module,
	)
}

func onClose() {
	conf.CloseAll()
	log.Info("all close")
	//log.CloseLogger()
}
